<Select DataSource="@_items"
		@bind-Value="@_selectedValue"
		EnableSearch
        Style="width: 200px;"
		ValueName="@nameof(Item.Value)"
		LabelName="@nameof(Item.Label)"
		TItemValue="string"
		TItem="Item"
        Placeholder="input search text"
        ShowArrowIcon="false"
		HideNotFoundContent="true"
        SearchDebounceMilliseconds="350"
        Loading="_loading"
        OnSearch="@(async (value) => await OnSearch(value))"
		OnSelectedItemChanged="OnSelectedItemChangedHandler">
</Select>

@using System.Web;
@using System.Text.Json;
@inject HttpClient Http
@code
{
    class Item
    {
        public string Value { get; set; }
        public string Label { get; set; }
    }

    Task<string> _oldTask;
    List<Item> _items = new List<Item>();
    string _selectedValue;
    bool _loading;

    private async Task OnSearch(string value)
    {
        if (!string.IsNullOrWhiteSpace(value))
        {
            if (_oldTask == null || _oldTask.IsCompleted)
            {
                _loading = true;
                StateHasChanged();

                var key = HttpUtility.UrlEncode(value);
                var url = $"https://suggest.taobao.com/sug?code=utf-8&q={key}";
        
                _oldTask = Http.GetStringAsync(url);
                var content = await _oldTask;

                var result = JsonSerializer.Deserialize<ApiResult>(content);
                _items.Clear();				
                foreach (var item in result.result)
                {
                    _items.Add(new Item { Value = item[0], Label = item[0]});
                }
            }
        }
        else
        {
            if (_items.Any())
                _items.Clear();
        }

        _loading = false;
        StateHasChanged();
    }

    private void OnSelectedItemChangedHandler(Item value)
    {
        Console.WriteLine($"selected: ${value?.Label}");
    }

    public class ApiResult
    {
        public List<string[]> result { get; set; }
    }
}
